import axios from 'axios'
import { takeEvery, put } from 'redux-saga/effects'
import * as types from './action-types'
import { initListAction } from './action-creators'

function* initList () {
  try {
    const res = yield axios.get('/api/todolist')
    const action = initListAction(res.data.result)
    yield put(action)
  } catch (err) {
    console.log('initList 報錯了')
  }
}

function* sagas () {
  yield takeEvery(types['GET_INIT_LIST'], initList)
}

export default sagas
